import pymysql
host='localhost'
user='root'
password='FW249746'
port=3306#默认3306，可不写
databse='commerce'
cursorclass=pymysql.cursors.DictCursor#是输出的元祖结果变成字典
db=pymysql.connect(host,user,password,databse,cursorclass=cursorclass)
#游标对象
cursor=db.cursor()
#编写sql语句并执行
sql='select * from com_user '#数据库的原生sql语句
cursor.execute(sql)
#输出结果
print(cursor.fetchone())#单条输出:fetchone
print(cursor.fetchone())
print(cursor.fetchone())
print(cursor.fetchall())
#print(cursor.fetchmany(3))#多条输出,放在一个元祖中
#关闭连接
cursor.close()
db.close()




















import pymysql
host='localhost'
user='root'
password='FW249746'
port=3306#默认3306，可不写
databse='iot'
cursorclass=pymysql.cursors.DictCursor#是输出的元祖结果变成字典
db=pymysql.connect(host,user,password,databse,cursorclass=cursorclass)
cursor=db.cursor()
sql='select * from user '
cursor.execute(sql)
print(cursor.fetchall())
cursor.close()
db.close()








